package com.biscuit.page.basicservice.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @author biscuit
 * @createTime 2024/6/8 9:37
 */
@Slf4j
public class JsonUtil {

    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

    public static <T> List<T> parseList(String json, Class<T> clazz) {
        try {
            // OBJECT_MAPPER.readValue(json, new TypeReference<List<AccountSettingVO.BackgroundImageItem>>() {});
            return OBJECT_MAPPER.readValue(json, OBJECT_MAPPER.getTypeFactory().constructCollectionType(List.class, clazz));
        } catch (Exception e) {
            log.error("JsonUtil parseList 转换失败，失败原因 => {}", e.getMessage());
        }
        return new ArrayList<>();
    }

}
